<?php
/**
 * Модель coupon
 * 
 * Класс модели
 * @author Anton Zavidov
 * @package myLiveShop
 */

/**
 * Модель coupon
 *
 */
class ModelCoupon extends Model {
	
	const TABLE				= 'coupon';
	const F_COUPON_ID  	= 'coupon_id';
	const F_HASH  	= 'hash';
	const F_SHOP_ID  	= 'shop_id';
	const F_USER_ID  	= 'user_id';
	const F_USED  	= 'used';
	const F_PERCENT  	= 'percent';
			
	public function __construct($className=null){
		parent::__construct(__CLASS__);
		$this->name='coupon';
		$this->id_field=array(self::F_COUPON_ID);
		$this->fields=array(
		self::TABLE.DOT.self::F_COUPON_ID=> new Field($this,self::F_COUPON_ID,self::TABLE,array(
				'auto'=>true,
				'important'=>true,
				'lenght'=>11)),
		self::TABLE.DOT.self::F_HASH=> new Field($this,self::F_HASH,self::TABLE,array(
				'lenght'=>8,
				'type'=>Field::TYPE_STRING)),
		self::TABLE.DOT.self::F_SHOP_ID=> new Field($this,self::F_SHOP_ID,self::TABLE,array(
				'lenght'=>9,
				'join_table'=>'shop')),
		self::TABLE.DOT.self::F_USER_ID=> new Field($this,self::F_USER_ID,self::TABLE,array(
				'lenght'=>11,
				'join_table'=>'user')),
		self::TABLE.DOT.self::F_USED=> new Field($this,self::F_USED,self::TABLE,array(
				'lenght'=>1,
				'validate_type'=>Validator::VALIDATE_BOOL)),
		self::TABLE.DOT.self::F_PERCENT=> new Field($this,self::F_PERCENT,self::TABLE,array(
				'lenght'=>2))		);
	}
}
